package com.alpha.eceasy.exception;

import lombok.Getter;
import lombok.NoArgsConstructor;

import java.io.Serial;

@Getter
@NoArgsConstructor
public class BizException extends RuntimeException {
    @Serial
    private static final long serialVersionUID = 1L;
    private Integer code;

    public BizException(String message) {
        super(message);
        this.code = ErrorCodeEnum.BAD_REQUEST.getCode();
    }

    public BizException(ErrorCodeEnum errorCode) {
        super(errorCode.getMsg());
        this.code = errorCode.getCode();
    }

    public BizException(ErrorCodeEnum errorCode, String message) {
        super(String.format("%s：%s", errorCode.getMsg(), message));
        this.code = errorCode.getCode();
    }

    public BizException(Integer code, String message) {
        super(message);
        this.code = code;
    }

    public BizException(Integer code, Throwable cause) {
        super(cause);
        this.code = code;
    }

    public BizException(Integer code, String message, Throwable cause) {
        super(message, cause);
        this.code = code;
    }

    public BizException(Integer code, String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
        super(message, cause, enableSuppression, writableStackTrace);
        this.code = code;
    }

    public BizException(ErrorCodeEnum code, Throwable cause) {
        super(code.getMsg(), cause);
        this.code = code.getCode();
    }
}
